import com.asap.demo.model.BeanField;
import com.asap.demo.model.StandardEvent;
import com.asap.demo.table.JsonField;
import com.asap.demo.table.RuleParse;
import com.asap.demo.utils.Utils;
import org.testng.annotations.Test;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.util.*;

/**
 * @author wangbh
 * @Description: test
 * @date 2021/7/12 15:32
 */
public class test {
    @Test
    public  void test_test1(){
        System.out.println(longDate(		1626866544000L));//2021-07-21 18:25:25
        System.out.println(Timestamp.valueOf("2021-07-09 18:15:21.001"));
        System.out.println(Instant.ofEpochMilli(1000));

        System.out.println( Timestamp.valueOf(Utils.transforDate("2021-07-21T19:22:24.001Z")).getTime());
        System.out.println( Utils.transforDateUtc1("2021-05-01 00:00:00.000"));

        System.out.println(Instant.ofEpochMilli(Timestamp.valueOf(Utils.transforDate("2021-07-21T19:22:24.001Z")).getTime()));
        BeanField beanField = new BeanField();
        Utils.setValue(beanField, "accountId", "1");
        Utils.setValue(beanField, "accountInOrgId", "2");

    }
    @Test
    public  void test1() {
        Integer result = Double.valueOf(String.valueOf(23)).intValue();
        RuleParse ruleParse = new RuleParse();
        Map properties = new HashMap();
        ruleParse.parseData("./conf/cfg.json");
        for (Object jsonField : ruleParse.getTableDefine().getJsonFieldList()) {
            JsonField jsonFieldBean = (JsonField) jsonField;
            String field = jsonFieldBean.getTopicFieldName();

            if (jsonFieldBean.getFieldType().equals("int")) {
                System.out.println("'"+field+"'" + " INTEGER,");
            } else if (jsonFieldBean.getFieldType().equals("date")) {
                System.out.println("'"+field+"'" + " TIMESTAMP_LTZ(3),");
            } else if (jsonFieldBean.getFieldType().equals("long")) {
                System.out.println("'"+field+"'" + " LONG,");
            } else {
                System.out.println("'"+field+"'" + " STRING,");
            }
        }
    }

    /**
     * 按yyyyMMddHHmmss格式获取当前日期
     *
     * @return
     */
    public static String longDate(long longDate) {
        // new日期对象
        Date date = new Date(longDate);
        // 转换提日期输出格式
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return dateFormat.format(date).toString();
    }

    public String getUrlByCode(String code) {
        char[] charArray = code.toCharArray();
        // A-Z 对应数字65-90 a-z 对应数字97-122
        for (int i = 0; i < charArray.length; i++) {
            if (charArray[i] == '_') {
                // 字符在97-122之间的都是小写字母，在原基础上减32转换成大写
                if (charArray[i + 1] >= 97 && charArray[i + 1] <= 122) {
                    int upper = charArray[i + 1] - 32;
                    charArray[i + 1] = (char) upper;
                }
            }
        }
        StringBuffer url = new StringBuffer("");
        for (int i = 0; i < charArray.length; i++) {
            url.append(charArray[i]);
        }
        return url.toString().replace("_", "");
    }
    @Test
    public void testForUrl(){
        try {
            while(true) {
                URL url = new URL("https://blog.csdn.net/yuyegongcheng/article/details/121360381");
                InputStream in = url.openStream();
                InputStreamReader isr = new InputStreamReader(in);
                BufferedReader bufr = new BufferedReader(isr);
                String str;
                while ((str = bufr.readLine()) != null) {
                    System.out.println(str);
                }
                bufr.close();
                isr.close();
                in.close();
                Thread.sleep(10000);
                System.out.println("+++++++");
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    @Test
    public void testForUrl1(){
        try {
            Random r = new Random(1);
            while(true) {

                int tmp = r.nextInt(10);
                System.out.println(Thread.currentThread().getId());
               // System.out.println(tmp%3);
                Thread.sleep(1000);
            }

//            while(true) {
//                URL url = new URL("https://www.toutiao.com/w/a1695559935696909/?log_from=6668c1346df7c_1637314669234");
//                HttpURLConnection connection = (HttpURLConnection) url.openConnection();
//                connection.connect();
//                System.out.println(connection.getURL());
//                // 发送数据到服务器并使用Reader读取返回的数据
//                BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
//
//                String lines;
//
//                while ((lines = reader.readLine()) != null) {
//                    System.out.println(lines);
//
//                }
//                reader.close();
//                connection.disconnect();
//                Thread.sleep(10000);



        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
